package cn.com.bdqn.controller;

import cn.com.bdqn.entity.SyArea;
import cn.com.bdqn.entity.SyMeterType;
import cn.com.bdqn.service.SyMeterTypeService;
import cn.com.bdqn.utils.ReturnData;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/syMeterType")
@Api(tags = "水表型号管理接口")
public class SyMeterTypeController {

    @Autowired
    private SyMeterTypeService syMeterTypeService;

    @Operation(summary = "查询所有水表型号信息")
    @PostMapping("/queryAll")
    public ReturnData queryAll(){
        try {
            List<SyMeterType> syMeterTypes = syMeterTypeService.queryAll();
            return ReturnData.ok().put("syMeterTypes",syMeterTypes);
        }catch (Exception e){
            return ReturnData.currError("查询所有水表型号信息数据库异常");
        }
    }

    @Operation(summary = "根据ID查询单个水表型号信息")
    @PostMapping("/queryById")
    public ReturnData queryById(Long id){
        try {
            SyMeterType syMeterType = syMeterTypeService.queryById(id);
            return ReturnData.ok().put("syMeterType",syMeterType);
        }catch (Exception e){
            return ReturnData.currError("根据ID查询单个水表型号信息数据库异常");
        }
    }

    @Operation(summary = "根据ID删除水表型号信息")
    @PostMapping("/delSyMeterType")
    public ReturnData delSyMeterType(Long id){
        int result = syMeterTypeService.delSyMeterType(id);
        if (result > 0){
            return ReturnData.ok();
        }else {
            return ReturnData.currError("删除水表型号信息数据库异常");
        }
    }

    @Operation(summary = "新增水表型号信息")
    @PostMapping("/addSyMeterType")
    public ReturnData addSyMeterType(SyMeterType syMeterType){
        int result = syMeterTypeService.addSyMeterType(syMeterType);
        if (result > 0){
            return ReturnData.ok();
        }else {
            return ReturnData.currError("新增水表型号信息数据库异常");
        }
    }

    @Operation(summary = "修改水表型号信息")
    @PostMapping("/updateSyMeterType")
    public ReturnData updateSyMeterType(SyMeterType syMeterType){
        int result = syMeterTypeService.updateSyMeterType(syMeterType);
        if (result > 0){
            return ReturnData.ok();
        }else {
            return ReturnData.currError("修改水表型号信息数据库异常");
        }
    }
}
